﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMMOCityPlayerPlugin.cpp
//    @Author           :    gaoyi
//    @Date             :    23-10-21
//    @Email			:    445267987@qq.com
//    @Module           :    NFMMOCityPlayerPlugin
//
// -------------------------------------------------------------------------

#include "NFMMOCityPlayerPlugin.h"

#include "CityDescEx.h"
#include "NFCityLoginModule.h"
#include "NFCityMapGrid.h"
#include "NFCityMapInst.h"
#include "NFCityMapMgr.h"
#include "NFCityMapModule.h"
#include "NFCityNpc.h"
#include "NFCityPlayer.h"
#include "NFComm/NFPluginModule/NFIPluginManager.h"
#include "NFCityPlayerModule.h"
#include "NFCitySession.h"
#include "NFCitySessionModule.h"
#include "DescStore/CityMapDesc.h"
#include "NFLogicCommon/NFBaseDefine.h"
#include "NFLogicCommon/NFCommDefine.h"

#ifdef NF_DYNAMIC_PLUGIN

NF_EXPORT void DllStartPlugin(NFIPluginManager* pm)
{
    CREATE_PLUGIN(pm, NFMMOCityPlayerPlugin)

};

NF_EXPORT void DllStopPlugin(NFIPluginManager* pm)
{
    DESTROY_PLUGIN(pm, NFMMOCityPlayerPlugin)
};

#endif


//////////////////////////////////////////////////////////////////////////

int NFMMOCityPlayerPlugin::GetPluginVersion()
{
    return 0;
}

std::string NFMMOCityPlayerPlugin::GetPluginName()
{
    return GET_CLASS_NAME(NFMMOCityPlayerPlugin);
}

void NFMMOCityPlayerPlugin::Install()
{
    REGISTER_MODULE(m_pObjPluginManager, NFCityPlayerModule, NFCityPlayerModule);
    REGISTER_MODULE(m_pObjPluginManager, NFCitySessionModule, NFCitySessionModule);
    REGISTER_MODULE(m_pObjPluginManager, NFCityMapModule, NFCityMapModule);
    REGISTER_MODULE(m_pObjPluginManager, NFCityLoginModule, NFCityLoginModule);
}

void NFMMOCityPlayerPlugin::Uninstall()
{
    UNREGISTER_MODULE(m_pObjPluginManager, NFCityPlayerModule, NFCityPlayerModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFCitySessionModule, NFCitySessionModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFCityMapModule, NFCityMapModule);
    UNREGISTER_MODULE(m_pObjPluginManager, NFCityLoginModule, NFCityLoginModule);
}

bool NFMMOCityPlayerPlugin::InitShmObjectRegister()
{
    NFServerConfig* pConfig = FindModule<NFIConfigModule>()->GetAppConfig(NF_ST_CITY_SERVER);
    NF_ASSERT(pConfig);

    uint32_t maxOnlinePlayerNum = pConfig->GetMaxOnlinePlayerNum() * 1.2;

    /////////////////////mgr//////////////////////
    REGISTER_SHM_OBJ(NFCityWorldObject, 0);
    REGISTER_SHM_OBJ_WITH_HASH(NFCityPlayer, maxOnlinePlayerNum);
    REGISTER_SHM_OBJ(NFCitySession, maxOnlinePlayerNum);
    REGISTER_SINGLETON_SHM_OBJ(NFCityMapMgr);

    int iMapInstNum = MAX_CITY_MAP_NUM + SNSSVR_MAX_GUILD_NUM_IN_HASH_TABLE;
    REGISTER_SHM_OBJ(NFCityMapInst, iMapInstNum);
    REGISTER_SHM_OBJ(NFCityMapGrid, MAX_CITY_MAP_NUM*MAX_MAP_GRID_NUM + SNSSVR_MAX_GUILD_NUM_IN_HASH_TABLE*MAX_GUILD_STATION_MAP_GRID_NUM);

    int iNpcNum = 50 * MAX_NPC_SPAWN_RECORD_NUM + SNSSVR_MAX_GUILD_NUM_IN_HASH_TABLE * 50;
    REGISTER_SHM_OBJ(NFCityNpc, iNpcNum);

    return true;
}
